package com.survey.utils;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class GsonUtils {

	public static Gson getGson() {
		Gson gson = new Gson();
		return gson;
	}

	public static JsonObject getValues(String value) {
		if(value != null) {			
			value = value.replaceAll("#", "");
			JsonParser jp = new JsonParser();
			JsonObject jsonObject = (JsonObject) jp.parse(value);
			return jsonObject;
		} else {
			return null;
		}
	}
	
	public static String getKey(String value, String key) {
		JsonObject jo = getValues(value);
		Object o = jo.get(key);
		if (o != null) {
			return jo.get(key).getAsString();
		} else {
			return null;
		}
	}
	
	public static String getKeyByValue(JsonObject jo, String key) {
		Object o = jo.get(key);
		if (o != null) {
			return jo.get(key).getAsString();
		} else {
			return null;
		}
	}
}
